package com.example.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.system.entity.User;
import com.example.system.mapper.UserMapper;
import com.example.system.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author baomidou
 * @since 2023-05-03
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Override
    public Map<String, Object> login(User user) {
        //根据用户名查询和密码查询
        LambdaQueryWrapper<User> wrapper= new LambdaQueryWrapper<>();
        wrapper.eq(User::getName,user.getName());
        wrapper.eq(User::getPassword,user.getPassword());
        User logginUser = this.baseMapper.selectOne(wrapper);
        //结果不为空生成token
        if(logginUser != null){
            //生成token
            String key = "user:"+ UUID.randomUUID();
            //返回数据
            Map<String,Object> data = new HashMap<>();
            data.put("token",key);
            return  data;
        }
        return null;
    }
}
